import com.google.common.collect.Lists;
import pub.tbc.rubbish.client.discovery.LoadBalancingHelper;
import pub.tbc.toolkit.Loops;

import java.util.List;

/**
 * @author tbc on 2016/12/10 14:16.
 */
public class LoadBalancing {
    public static void main(String[] args) {
        List<String> services = Lists.newArrayList("it", "it:8080", "it:7001");

        simpleRandom(services);
        System.out.println("\n");
        rotate("itSevice", services);
    }

    private static void simpleRandom(List<String> services) {
        Loops.times(9, i -> System.out.println(LoadBalancingHelper.simpleRandom(services)));
    }

    private static void rotate(String serviceName, List<String> services) {
        Loops.times(3, i -> new Thread(() -> Loops.times(9, j -> System.out.println("Thread: " + Thread.currentThread().getName() + " ->" + LoadBalancingHelper.rotate(serviceName, services)))).start());
//        for (int i = 0; i < 3; i++) {
//            new Thread(() ->
//                    Loops.times(9, j ->
//                            System.out.println("Thread: " + Thread.currentThread().getName() + " ->" + LoadBalancingHelper.rotate(serviceName, services))
//                    )
//            ).start();
//        }
    }
}